package one.chchy.demo.sprintsecurity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by lutery on 2017/8/11.
 */
public class JwtUserFactory {

    public static JwtUser produce(String username, String password, List<String> authorities){
        return new JwtUser(username, password, mapToGrantedAuth(authorities));
    }

    private static List<GrantedAuthority> mapToGrantedAuth(List<String> authorities){
        return authorities.stream()
                .map(SimpleGrantedAuthority::new)
                .collect(Collectors.toList());
    }
}
